package com.example.recordingpen_datacollection.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.recordingpen_datacollection.entity.AdminUser;
import com.example.recordingpen_datacollection.entity.Vo.AdminPasswordVo;
import com.example.recordingpen_datacollection.entity.Vo.AdminUserEnrollVo;
import com.example.recordingpen_datacollection.entity.Vo.AdminUserLoginVo;
import com.example.recordingpen_datacollection.mapper.AdminUserMapper;
import com.example.recordingpen_datacollection.service.AdminUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xg
 * @since 2024-06-06
 */
@Service
public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser> implements AdminUserService {

    @Override
    public boolean setsetAdminUser(AdminUserEnrollVo adminUserEnrollVo) {
        AdminUser adminUser = new AdminUser();
        adminUser.setAdname(adminUserEnrollVo.getAdname());
        adminUser.setAccount(adminUserEnrollVo.getAccount());
        adminUser.setPassword(adminUserEnrollVo.getPassword());
        boolean save = this.save(adminUser);
        return save;
    }

    @Override
    public AdminUser loginAdminUser(AdminUserLoginVo adminUserLoginVo) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("account",adminUserLoginVo.getAccount());
        wrapper.eq("password",adminUserLoginVo.getPassword());
        AdminUser one = this.getOne(wrapper);
        return one;
    }

    @Override
    public boolean alterAdminPassword(AdminPasswordVo adminPassword, Integer value) {
        AdminUser adminUser = new AdminUser();
        adminUser.setAdid(value);
        adminUser.setPassword(adminPassword.getNewpassword());
        boolean update = this.updateById(adminUser);
        return update;
    }
}
